<?php

class EntrenarController extends Controller
{
	public function actionIndex()
	{
		$cs = Yii::app()->getClientScript();
		$cs->registerScriptFile($this->module->assetsUrl.'/js/webcam.min.js');
		$cs->registerCoreScript('jquery');
		$this->render('index');
	}

	public function actionList()
	{
		$cs = Yii::app()->getClientScript();
		$cs->registerScriptFile($this->module->assetsUrl.'/js/webcam.min.js');
		$cs->registerCoreScript('jquery');
		$this->render('list');
	}

	public function actionGetPhoto($id = null)
	{
		if (Yii::app()->request->isAjaxRequest)
		{
			if(isset($_FILES['webcam']))
			{
				if ($id == null)
				{
					if (isset(Yii::app()->user->id))
						$id = Yii::app()->user->id;
					else
						Message::flash('error', 'Debe iniciar sesión o seleccionar un usuario de la lista (si está disponible) para registrar la foto.');
				}
				if ($id != null)
				{
					$this->module->facial->uploadGallery($_FILES['webcam']['tmp_name'], $id.'.png');
					Message::flash('success','Imagen almacenada exitosamente.');
				}
				Yii::app()->end();
			}
		}
		throw new CHttpException(403,Yii::t('yii', 'You are not authorized to perform this action.'));
	}
};